package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Result;
import com.itheima.servise.DeptServise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptServise deptServise;
    //部门列表查询
    @GetMapping
    public Result list(){
        return Result.success(deptServise.getAll());
    }
    //根据id删除部门
    @DeleteMapping
    public Result delete(Integer id){
        deptServise.deleteClass(id);
        return Result.success();
    }
    //添加部门
    @PostMapping
    public Result add(@RequestBody Dept dept){
        deptServise.addClass(dept);
        return Result.success();
    }
    //根据Id查询部门
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        return Result.success(deptServise.getById(id));
    }
    //修改部门
//    @PutMapping
//    public Result update(@RequestBody Dept dept){
//        System.out.println(dept);
//        deptServise.putClass(dept);
//        return Result.success();
//    }
    @PutMapping
    public Result update(@RequestBody Dept dept){
        deptServise.putClass(dept);
        return Result.success();
    }
}
